#!/bin/sh
# git push -u origin pesomama
# git checkout -b pesomama
#npm install -g grunt-node-inspector

echo 'Updating...'
# update codes
git branch;
git pull;
npm install;

echo 'Deleting...'
# delete dist
expect -c "
set timeout 5
spawn sudo rm -fr dist
expect \"*assword\" { send \"Zxc1234567\r\" }
expect eof"

# delete dist.zip
expect -c "
set timeout 5
spawn sudo rm -fr dist.zip
expect \"*assword\" { send \"Zxc1234567\r\" }
expect eof"

# delete /home/ubuntu/web/*.zip from pck-as-01
expect -c "
spawn ssh -t yfdev@172.16.50.165 rm -fr /home/yfdev/web/*.zip
expect {
\"*assword\" {set timeout 300; send \"123456\r\";}
\"yes/no\" {send \"yes\r\"; exp_continue;}
}
expect eof"

echo 'Building...'
# build dist
expect -c "
set timeout 5000
spawn sudo npm run build
expect \"*assword\" { send \"Zxc1234567\r\" }
expect eof"

# zip dist.zip
echo 'Ziping...'
zip -r dist.zip dist

echo 'Copying...'
# copy dist.zip to pck-as-01
expect -c "
spawn scp -r ./dist.zip yfdev@172.16.50.165:/home/yfdev/web
expect {
\"*assword\" {set timeout 300; send \"123456\r\";}
\"yes/no\" {send \"yes\r\"; exp_continue;}
}
expect eof"

echo 'Logining...'
# login to pck-as-01
expect -c "
set timeout 5
spawn ssh -t yfdev@172.16.50.165 sudo su
expect \"*assword\" { send \"123456\r\" }
expect \"*assword for yfdev\" { send \"123456\r\" }
expect \"#\" { send \"cd /home/yfdev/web\r\" }
expect \"#\" { send \"sh yenbai-dp.sh\r\" }
interact"
